package com.atguigu.oss.controller;

import com.atguigu.commonUtils.Result;
import com.atguigu.commonUtils.ResultUtil;
import com.atguigu.oss.service.OssService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;


@Api(tags = "OSS文件存储")
@RestController
@RequestMapping("/eduOSS/fileOSS")
@CrossOrigin
public class OssController {

    @Resource
    private OssService ossService;

    @ApiOperation("上传讲师头像")
    @PostMapping("/uploadHead")
    public Result<Map<String,String>> uploadHead(MultipartFile file){
        String filePath = "teacher_head";
        String url = ossService.uploadAvatar(file, filePath);
        Map<String,String> map = new HashMap<>();
        map.put("url",url);
        return ResultUtil.success(map);
    }

    @ApiOperation("上传课程封面")
    @PostMapping("/uploadCourse")
    public Result<Map<String,String>> updateCourse(MultipartFile file){
        String filePath = "course_image";
        String url = ossService.uploadAvatar(file, filePath);
        Map<String,String> map = new HashMap<>();
        map.put("url",url);
        return ResultUtil.success(map);
    }



}
